﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnesSystem.Controls.CommonTables.CQ.NTZYY
{
    /// <summary>
    /// ShuHouFangShiCtrl.xaml 的交互逻辑
    /// </summary>

    public partial class ShuHouFangShiCtrl : CustomCommonTableCtrl
    {
        public ShuHouFangShiCtrl()
        {
            InitializeComponent();
           
            qm.CheckChanged += CustomCheckBoxCtrl_CheckChanged;
            sjzz.CheckChanged += CustomCheckBoxCtrl_CheckChanged_1;
            zgmz.CheckChanged += CustomCheckBoxCtrl_CheckChanged_2;
            wbfz.CheckChanged += CustomCheckBoxCtrl_CheckChanged_3;
            ybfz.CheckChanged += ybfz_CheckChanged; yt.CheckChanged += ybfz_CheckChanged;
            sysy.CheckChanged += ybfz_CheckChanged; dyxz.CheckChanged += ybfz_CheckChanged;
            ccdgr.CheckChanged += ybfz_CheckChanged; jbxz.CheckChanged += ybfz_CheckChanged;
            tt.CheckChanged += ybfz_CheckChanged; ty.CheckChanged += ybfz_CheckChanged;
            ydza.CheckChanged += ybfz_CheckChanged; gjza.CheckChanged += ybfz_CheckChanged;
            ex.CheckChanged += ybfz_CheckChanged; ot.CheckChanged += ybfz_CheckChanged;
            qmqt.ValueChanged += qmqt_ValueChanged;

            IniteRadioBation();
           
            getAnestoredMzff();
            this.Loaded += ShuHouFangShiCtrl_Loaded;
           
        }

        private void Qmqt_ValueChanged(object sender, EventArgs e)
        {
            
        }

        private void ShuHouFangShiCtrl_Loaded(object sender, RoutedEventArgs e)
        {
        }

        private void CustomCheckBoxCtrl_CheckChanged(object sender, RoutedEventArgs e)
        {
            CustomCheckBoxCtrl check = sender as CustomCheckBoxCtrl;
            string text1 = null;
            if (jlsj.Value == null || jlsj.Value.Equals(""))
            {
               text1 = DateTime.Now.ToString(DateFormat.DATE_FORMAT_STR_YMDHMS);
            }
            else
            {
                text1 = jlsj.Value.ToString();
            }
            bool cutrue = check.IsChecked;
            if (cutrue)
            {
                fxyj.Value =fxyj.Value+"于"+text1+"随访，患者神志清楚，精神良好，诉术后镇痛效果好，无咽痛、声音嘶哑，无PONV，无头晕头痛。自主呼吸好，咳嗽排痰有力，生命体征在正常范围，心肺未闻及异常，腹平坦无膨隆，无尿潴留。";
            }
        }

        private void CustomCheckBoxCtrl_CheckChanged_1(object sender, RoutedEventArgs e)
        {
            CustomCheckBoxCtrl check = sender as CustomCheckBoxCtrl;
            string text1 = null;
            if (jlsj.Value == null || jlsj.Value.Equals(""))
            {
                text1 = DateTime.Now.ToString(DateFormat.DATE_FORMAT_STR_YMDHMS);
            }
            else
            {
                text1 = jlsj.Value.ToString();
            }
            bool cutrue = check.IsChecked;
            if (cutrue)
            {
                fxyj.Value = fxyj.Value + "于" + text1 + "随访，患者神志清楚，精神稍差，诉切口疼痛（术后镇痛效果好），无声音嘶哑，无胸闷，无PONV。自主呼吸好，咳嗽排痰有力，生命体征在正常范围，穿刺点无血肿，麻醉区域痛触觉及肌力恢复如前。";
            }

        }

        private void CustomCheckBoxCtrl_CheckChanged_2(object sender, RoutedEventArgs e)
        {
            CustomCheckBoxCtrl check = sender as CustomCheckBoxCtrl;
            bool cutrue = check.IsChecked;
            string text1 = null;
            if (jlsj.Value == null || jlsj.Value.Equals(""))
            {
                text1 = DateTime.Now.ToString(DateFormat.DATE_FORMAT_STR_YMDHMS);
            }
            else
            {
                text1 = jlsj.Value.ToString();
            }
            if (cutrue)
            {
                fxyj.Value = fxyj.Value + "于" + text1 + "患者神志清楚，精神稍差，诉术后镇痛效果好，无PONV，无头晕头痛及视听觉异常。生命体征在正常范围，无颈项强直，穿刺点无红肿、压痛，麻醉区域痛触觉及肌力恢复如前。";
            }
        }

        private void CustomCheckBoxCtrl_CheckChanged_3(object sender, RoutedEventArgs e)
        {
            CustomCheckBoxCtrl check = sender as CustomCheckBoxCtrl;
            List<string> ybfzList = DataManager.Instance.GetXMLTableValue(DataManager.Instance.CurrentPatientLink, "ShuHouFangShi", "qmybfz", "yantong", "sysy", "dyxz", "qgqk", "bfnbg", "icubg", "xsrwbg24", "icubg", "gjza", "ydza", "fbw", "fby");
            
            bool cutrue = check.IsChecked;
            if (cutrue)
            {
                ybfz.Value = false;
                yt.Value = false;
                sysy.Value = false;
                dyxz.Value = false;
                ccdgr.Value = false;
                jbxz.Value = false;
                tt.Value = false;
                ty.Value = false;
                ydza.Value = false;
                gjza.Value = false;
                ex.Value = false;
                ot.Value = false; 
                qmqt.Value = "";

                ybfz.Value = false;
                exing.Value = "无";
                outu.Value = "无";
                saoyang.Value = "无";
                niaochuliu.Value = "无";
                yundong.Value = "无";
                ganjue.Value = "无";

            }
            else
            {
                exing.Value = null;
                outu.Value = null;
                saoyang.Value = null;
                niaochuliu.Value = null;
                yundong.Value = null;
                ganjue.Value = null;
            }
        }

        private void jlsj_GotFocus(object sender, RoutedEventArgs e)
        {
            CusDatePickerWin cusDatePicker = new CusDatePickerWin();
            cusDatePicker.SelectedDateTime = DateTime.Now;
            cusDatePicker.ShowDialog();
           
            if (cusDatePicker.Result)
            {
                jlsj.Value = cusDatePicker.SelectedDateTime.ToString(DateFormat.DATE_FORMAT_STR_YMDHM);//2005年11月5日
            }

        }

        private void rq_GotFocus(object sender, RoutedEventArgs e)
        {
            CusDatePickerWin cusDatePicker = new CusDatePickerWin();
            cusDatePicker.SelectedDateTime = DateTime.Now;
            cusDatePicker.ShowDialog();
            if (cusDatePicker.Result)
            {
                rq.Value = cusDatePicker.SelectedDateTime.ToString(DateFormat.DATE_FORMAT_STR_YMD_CN);//2005年11月5日
            }
        }
        private void IniteRadioBation()
        {
            new RadioButtonHelper().ChangeRadioSatus(smtzbwd, smtzwd);
            new RadioButtonHelper().ChangeRadioSatus(ysbqc, ysqc);
            new RadioButtonHelper().ChangeRadioSatus(hxkn,hxzc);
            new RadioButtonHelper().ChangeRadioSatus(xhbwd,xhwd );
        }

       

        private void ybfz_CheckChanged(object sender, RoutedEventArgs e)
        {
            CustomCheckBoxCtrl cucheck = sender as CustomCheckBoxCtrl;
            bool cutrue = cucheck.IsChecked;
            if (cutrue)
            {
                wbfz.Value = false;
            }
        }

        private void qmqt_ValueChanged(object sender, EventArgs e)
        {
            string qmst = qmqt.Value.ToString();
            if (!string.IsNullOrEmpty(qmst))
            {
                wbfz.Value = false;
            }
        }

        private void getAnestoredMzff()
        {
            if (DataManager.Instance.CurrentPatientLink == null) return;
            string mzff = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Mzff;
            if (!qm.IsChecked && !zgmz.IsChecked && !sjzz.IsChecked&&mzff!=null)
            {

           
                if (mzff.Contains("全麻"))
            {
                qm.Value = true;
            }
            if (mzff.Contains("椎管内麻醉"))
            {
                zgmz.Value = true;
            }
            if (mzff.Contains("神经阻滞"))
            {
                sjzz.Value = true;
            }
            }
        }
    }
}
